from django.shortcuts import render,HttpResponse
from django.core.paginator import Paginator
from .models import *
# Create your views here.
# 添加
def stu_add(request):
    if request.method =='GET':
        return render(request,'add.html')
    if request.method == 'POST':
        stu_name = request.POST.get('stu_name')
        sex = request.POST.get('sex')
        stu_class = request.POST.get('stu_class')
        specialized = request.POST.get('specialized')
        img_path = request.POST.get('img_path')
        q1= Student(
            stu_class=stu_class,
            stu_name=stu_name,
            sex=sex,
            specialized=specialized,
            img_path=img_path
        )
        q1.save()
        result = '插入成功'
        return render(request,'add.html',{'result':result})
def stuList(request):
    stu_show = Student.objects.all()
    paginator = Paginator(stu_show,3)
    x= request.GET.get('page',2)
    try:
        x = int(x)
        if x < 0:
            x = 1
    except Exception as e:
        x = 1

    pagex = paginator.get_page(x)

    return render(request, 'index.html', {'pagex': pagex})
def stu_del(request):
    s2 = Student.objects.filter(id=1).delete()
    return HttpResponse('成功')
def stu_get(request):
    return render(request,'stu_info.html')